package hr.sting.droidorm.dao;

import hr.sting.droidorm.DroidOrmCursor;
import hr.sting.droidorm.DroidOrmManager;

import java.util.List;

/**
 * @author mstipanov
 * @since 12.09.2010. 18:23:54
 */
public abstract class AbstractOrmDataService<T> implements DataService<T> {
    private BasicOrmDataService basicOrmDataService;
    protected Class<T> entityType;

    protected AbstractOrmDataService(Class<T> entityType) {
        this.entityType = entityType;
        basicOrmDataService = new BasicOrmDataService();
    }

    public void setDroidOrmManager(DroidOrmManager droidOrmManager) {
        basicOrmDataService.setDroidOrmManager(droidOrmManager);
    }

    protected DroidOrmTemplate getDroidOrmTemplate() {
        return basicOrmDataService.getDroidOrmTemplate();
    }

    @Override
    public DroidOrmCursor<T> findAll() {
        return basicOrmDataService.findAll(entityType);
    }

    @Override
    public T findById(Object id) {
        return basicOrmDataService.findById(entityType, id);
    }

    @Override
    public void saveAll(List<T> list) {
        basicOrmDataService.saveAll(list);
    }

    @Override
    public void save(T t) {
        basicOrmDataService.save(t);
    }

    @Override
    public void delete(T t) {
        basicOrmDataService.delete(t);
    }
}
